package com.mytool.service.impl;

import org.springframework.stereotype.Component;

/**
 * 文件路径解析器，负责确定生成的文件应该存储的位置
 */
@Component
public class FilepathResolver {

    /**
     * 获取文件路径
     * 
     * @param templateKey 模板键
     * @param packagePrefix 包前缀
     * @param domainObjectName 领域对象名
     * @param tableName 表名
     * @return 文件路径
     */
    public String getFilePath(String templateKey, String packagePrefix, String domainObjectName, String tableName) {
        String basePath = packagePrefix.replace(".", "/");
        
        switch (templateKey) {
            // Spring Boot 3.3.0架构相关文件路径
            case "entity":
                return basePath + "/domain/entity/" + domainObjectName + ".java";
            case "repository":
                return basePath + "/infrastructure/repository/" + domainObjectName + "Repository.java";
            case "service":
                return basePath + "/domain/service/" + domainObjectName + "Service.java";
            case "serviceImpl":
                return basePath + "/domain/service/impl/" + domainObjectName + "ServiceImpl.java";
            case "controller":
                return basePath + "/controller/" + domainObjectName + "Controller.java";
            
            // COLA架构相关文件路径
            case "domain-entity":
                return basePath + "/domain/model/" + tableName.toLowerCase() + "/" + domainObjectName + ".java";
            case "data-object":
                return basePath + "/infrastructure/dataobject/" + domainObjectName + "DO.java";
            case "dto":
                return basePath + "/client/dto/data/" + domainObjectName + "DTO.java";
            case "add-command":
                return basePath + "/client/dto/command/" + domainObjectName + "AddCmd.java";
            case "modify-command":
                return basePath + "/client/dto/command/" + domainObjectName + "ModifyCmd.java";
            case "get-query":
                return basePath + "/client/dto/query/" + domainObjectName + "GetQry.java";
            case "list-query":
                return basePath + "/client/dto/query/" + domainObjectName + "ListQry.java";
            case "gateway":
                return basePath + "/domain/gateway/" + domainObjectName + "Gateway.java";
            case "service-interface":
                return basePath + "/client/api/" + domainObjectName + "ServiceI.java";
            case "service-impl":
                return basePath + "/application/service/impl/" + domainObjectName + "ServiceImpl.java";
            case "repository-interface":
                return basePath + "/domain/gateway/" + domainObjectName + "Repository.java";
            case "repository-impl":
                return basePath + "/infrastructure/repository/" + domainObjectName + "RepositoryImpl.java";
            case "mapper":
                return basePath + "/infrastructure/mapper/" + domainObjectName + "Mapper.java";
            case "mapper-xml":
                return "src/main/resources/mapper/" + domainObjectName + "Mapper.xml";
            case "add-cmd-exe":
                return basePath + "/application/executor/" + tableName.toLowerCase() + "/" + domainObjectName + "AddCmdExe.java";
            case "modify-cmd-exe":
                return basePath + "/application/executor/" + tableName.toLowerCase() + "/" + domainObjectName + "ModifyCmdExe.java";
            case "get-qry-exe":
                return basePath + "/application/executor/" + tableName.toLowerCase() + "/" + domainObjectName + "GetQryExe.java";
            case "list-qry-exe":
                return basePath + "/application/executor/" + tableName.toLowerCase() + "/" + domainObjectName + "ListQryExe.java";
            case "assembler":
                return basePath + "/application/assembler/" + domainObjectName + "Assembler.java";
            case "domain-converter":
                return basePath + "/infrastructure/converter/" + domainObjectName + "Converter.java";
            case "domain-event":
                return basePath + "/domain/event/" + domainObjectName + "Event.java";
            case "value-object":
                return basePath + "/domain/model/" + tableName.toLowerCase() + "/" + domainObjectName + "Value.java";
            case "domain-service":
                return basePath + "/domain/service/" + domainObjectName + "DomainService.java";
            case "adapter":
                return basePath + "/adapter/web/" + tableName.toLowerCase() + "/" + domainObjectName + "Controller.java";
            case "external-dto":
                return basePath + "/client/dto/external/" + domainObjectName + "ExternalDTO.java";
            case "domain-event-publisher":
                return basePath + "/domain/event/" + domainObjectName + "EventPublisher.java";
            case "external-system-exception":
                return basePath + "/client/exception/" + domainObjectName + "ExternalException.java";
            default:
                return null;
        }
    }
    
    /**
     * 获取测试文件路径
     * 
     * @param templateKey 模板键
     * @param packagePrefix 包前缀
     * @param domainObjectName 领域对象名
     * @param tableName 表名
     * @return 测试文件路径
     */
    public String getTestFilePath(String templateKey, String packagePrefix, String domainObjectName, String tableName) {
        String basePath = "src/test/java/" + packagePrefix.replace(".", "/");
        
        switch (templateKey) {
            case "controller-test":
                return basePath + "/controller/" + domainObjectName + "ControllerTest.java";
            case "service-test":
                return basePath + "/domain/service/" + domainObjectName + "ServiceTest.java";
            case "repository-test":
                return basePath + "/infrastructure/repository/" + domainObjectName + "RepositoryTest.java";
            case "mapper-test":
                return basePath + "/infrastructure/mapper/" + domainObjectName + "MapperTest.java";
            default:
                return null;
        }
    }
} 